import { _decorator, Component, Node, Label, tween, v3, Tween, Vec2, v2, Vec3, UITransform, UIOpacity } from 'cc';
import { PoolManager } from '../Manager/PoolManager';

const { ccclass, property } = _decorator;

@ccclass('Tip')
export default class Tip extends Component {
    maskUT: UITransform = null!;
    tipUT: UITransform = null!;
    tipLb: Label = null!;

    onLoad() {
        this.maskUT = this.node.getChildByName(`Mask`).getComponent(UITransform);
        this.tipUT = this.node.getChildByName(`TipLb`).getComponent(UITransform);;
        this.tipLb = this.node.getChildByName(`TipLb`).getComponent(Label);
    }

    Show(content: string) {
        this.tipLb.string = `${content}`;
        this.tipLb.updateRenderData(true);
        this.maskUT.setContentSize(this.tipUT.contentSize.width + 200, this.tipUT.contentSize.height + 10);

        this.ShowTween();
    }

    ShowTween() {
        this.node.scale = Vec3.ZERO;
        this.node.setPosition(Vec3.ZERO);
        Tween.stopAllByTarget(this.node);

        tween(this.node)
            .to(0.5, { scale: v3(1, 1) }, { easing: `elasticOut` })
            .delay(0.75)
            .to(0.25, { position: v3(0, 150), scale: v3(0, 0) })
            .call(() => {
                PoolManager.Instance.PutNode(this.node);
            })
            .start();
    }
}
